const fs = require('fs');
const url  = require('url');


getUrl('http://jandan.net/ooxx/page-1',data=>{
    console.log(data.toString())
})




function getUrl(surl, success) {
    var urlObj  = url.parse(surl);
    var http ='';
    if(urlObj.protocol == 'http:'){
        http = require('http');
    }
    else{
        http = require('https');
    }

    let req = http.request({
        'hostname':urlObj.hostname,
        'path':urlObj.path
    },res=>{
        var arr = [];

        res.on('data',buffer=>{
            arr.push(buffer);
        });
        res.on('end',()=>{
            let b = Buffer.concat(arr);
            success && success(b);
            console.log(b)
        })


    });

    req.end();
    req.on('error',()=>{
        console.log('404了，哥们');
    })
}